<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="asc.biz.vo.AscCounsel"%>
<%
	String counselList = (String)request.getAttribute("counselList");
AscCounsel counseldata = (AscCounsel)request.getAttribute("counseldata");
%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8" />
<meta http-equiv="Cache-Control" content="No-Cache" />
<meta http-equiv="Pragma" content="No-Cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>상담내역관리</title>
<link rel="stylesheet" type="text/css" href="/resources/theme/metro-blue/easyui.css" />
<link rel="stylesheet" type="text/css" href="/resources/theme/icon.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/ui_custom.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/design.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/form.css" />
<!--[if lt IE 9]>
	<script type="text/javascript" src="/resources/js/html5.js" /></script>
<![endif]-->
<script type="text/javascript" src="/resources/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/resources/js/jquery.jclock.js"></script>
<script type="text/javascript" src="/resources/js/common.js" /></script>
<script type="text/javascript" src="/resources/js/is.validate.js" /></script>

<script type="text/javascript" language="javascript">
function getListEnter(){
	if(event.keyCode != 13){
		return false;
	}else{
		getList();
	}
}
function getList(isClear){
	if(isClear){
		document.form.pageNo.value = 1;
		document.form.pageSize.value = 20;
	} 
	if( document.form.searchCounselType.value == "" && 
		document.form.searchCounselor.value == "" && 
		document.form.searchCounselee.value == "" && 
		document.form.searchCounseleePhone.value == "" 
		){
		alert("검색어를 입력하세요");
		return;
	}
	document.form.target = "_self";
	document.form.action="/counsel_list.do";
	document.form.submit();
}

/* function clearData(){
	document.form.dataCustIdx.value = 0;
	document.form.dataCustCode.value = "";
	document.form.dataCustName.value = "";
	document.form.dataCustPhone.value = "";
	document.form.dataCustBoss.value = "";
	document.form.dataCustAddr.value = "";
} */
function saveData(){
	if(validate()){
		document.form.target = "behindFrame";
		document.form.action="/counsel_save.do";
		document.form.submit();
	}
}
/* function deleteData(){
	if(confirm("["+document.form.dataCustName.value + "]을(를) 삭제하시겠습니까?")){
		document.form.target = "behindFrame";
		document.form.action="/counsel_delete.do";
		document.form.submit();	
	}
} */

function reload(returnVal, type){
	
	if(returnVal==-1){
		switch(type){
		case "C": 
			alert("저장중 에러가 발생 하였습니다.");
			break;
		case "U": 
			alert("수정중 에러가 발생 하였습니다.");
			break;
		case "D": 
			alert("삭제중 에러가 발생 하였습니다.");
			break;
		}
	}else{
		switch(type){
		case "C": 
			alert("저장되었습니다.");
			break;
		case "U": 
			alert("수정되었습니다.");
			break;
		case "D": 
			alert("삭제되었습니다.");
			break;
		}

		document.form.target = "_self";
		document.form.action="/counsel_list.do";
		document.form.submit();	
	}
}

function validate(){
	
	var form = document.form;

	if(form.dataCustCode.value == ""){
		alert("고객코드를 입력하세요.");
		form.dataCustCode.focus();
		return false;
	}else{
		if(!isValideBytes(form.dataCustCode, "고객코드")){
			return false;
		}
	}
	if(form.dataCustName.value == ""){
		alert("업체명을 입력하세요.");
		form.dataCustName.focus();
		return false;
	}else{
		if(!isValideBytes(form.dataCustName, "업체명")){
			return false;
		}
	}
	if(form.dataCustPhone.value == ""){
		alert("전화번호를 입력하세요.");
		form.dataCustPhone.focus();
		return false;
	}else{
		if(!isValideBytes(form.dataCustPhone, "전화번호")){
			return false;
		}
	}
	if(form.dataCustBoss.value == ""){
		alert("대표자를 입력하세요.");
		form.dataCustBoss.focus();
		return false;
	}else{
		if(!isValideBytes(form.dataCustBoss, "대표자")){
			return false;
		}
	}
	if(form.dataCustAddr.value == ""){
		alert("주소를 입력하세요.");
		form.dataCustAddr.focus();
		return false;
	}else{
		if(!isValideBytes(form.dataCustAddr, "주소")){
			return false;
		}
	}
	
	return true;
}

function getExcel(){
	document.form.target = "_self";
	document.form.action="/customer_excel.do";
	document.form.submit();
}
</script>
</head>
	
<body class="pop easyui-layout">
<form method="POST" name="form">
<iframe id="behindFrame" name="behindFrame"></iframe>
<input type="hidden" name="searchCounselIdx" value="<%=counseldata.getSearchCounselIdx()%>"/>
<input type="hidden" name="dataCounselIdx" value="0"/>
<input type="hidden" name="pageNo" value="<%=counseldata.getPageNo()%>">
<input type="hidden" name="pageSize" value="<%=counseldata.getPageSize()%>">
	<div data-options="region:'center',border:false,iconCls:'icon-head02',title:'상담내역관리'">	
	
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center',border:false">
				<div class="easyui-panel bb0" data-options="border:false,fit:true">
					<table id="grid_counsel" class="easyui-datagrid"></table>
							
					<div id="tb_custom" class="datagrid-toolbar wrap_tbl_toolbar">	
						<table class="tbl_inner">	
							<colgroup>
								<col width="55px">
								<col width="120px">
								<col width="45px">
								<col width="120px">
								<col width="80px">
								<col width="120px">
							</colgroup>
							<tr>
								<th>상담일자</th>
								<td class="formText"><input class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" name="searchFromDate" value="<%=counseldata.getSearchFromDate()%>" onKeyPress="getListEnter();"/></td>
								<th>~</th>
								<td class="formText"><input class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" name="searchToDate" value="<%=counseldata.getSearchToDate()%>" onKeyPress="getListEnter();"/></td>
								<th>상담유형</th>
								<td class="formText"><input type="text" name="searchCounselType" value="<%=counseldata.getSearchCounselType()%>" onKeyPress="getListEnter();"/></td>
								<th>상담원</th>
								<td class="formText"><input type="text" name="searchCounselor" value="<%=counseldata.getSearchCounselor()%>" onKeyPress="getListEnter();"/></td>
							</tr>
							<tr>	
								<th>고객명</th>
								<td class="formText"><input type="text" name="searchCounselee" value="<%=counseldata.getSearchCounselee()%>" onKeyPress="getListEnter();"/></td>
								<th>전화번호</th>
								<td class="formText"><input type="text" name="searchCounseleePhone" value="<%=counseldata.getSearchCounseleePhone()%>" onKeyPress="getListEnter();"/></td>
								<td><a href="javascript:getList();"class="easyui-linkbutton" data-options="iconCls:'icon-search'">조회</a>
								<a href="javascript:getExcel();" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">엑셀저장</a>
							</tr>
						</table>
					</div>
				</div>
			</div>
			<div data-options="region:'south',border:false">
					<div data-options="region:'north',border:false">
					<div id="pp" class="easyui-pagination"></div>
					</div>
				<div class="easyui-panel combobox-item-selected padding5" data-options="fit:true" style="height:110px;overflow:hidden">
					<div class="wrap_tbl_inner">	
						<table class="tbl_inner">	
							<colgroup>
								<col width="55px">
								<col width="120px">
								<col width="45px">
								<col>
								<col width="60px">
								<col width="120px">
							</colgroup>
							<tr>
								<th>고객명</th>
								<td class="formText"><input type="text" name="dataCustCode" value="" MAXBYTE="10"></td>
								<th>업체명</th>
								<td class="formText"><input type="text" name="dataCustName" value="" MAXBYTE="50"></td>
								<th>전화번호</th>
								<td class="formText"><input type="text" name="dataCustPhone" value="" MAXBYTE="20"></td>
							</tr>
							<tr>
								<th>대표자</th>
								<td class="formText"><input type="text" name="dataCustBoss" value="" MAXBYTE="20"></td>
								<th>주소</th>
								<td colspan="3" class="formText"><input type="text" name="dataCustAddr" value="" MAXBYTE="100"></td>
							</tr>
						</table>						
					</div>
					<div class="btn_area">
						<a href="javascript:clearData();" class="easyui-linkbutton">초기화</a>
						<a href="javascript:saveData();" class="easyui-linkbutton">저장</a>
						<a href="javascript:deleteData();" class="easyui-linkbutton">삭제</a>
					</div>
				</div>
			</div>
		</div>
		
	</div>

	<div data-options="region:'south',border:false" class="layout_south alignL">
		Copyright 2013 Suwon City Facilities Management Corporation. All rights reserved.
		<p class="btn_close" title="닫기" onclick="window.close()"></p>
	</div>
		
</form>
<script type="text/javascript">
//그리드
$('#grid_counsel').datagrid({
	rownumbers:true,
    fitColumns: true,
    singleSelect: true,
    fit: true,
    striped: true,
    toolbar:'#tb_custom',
    //pagination: true,
    nowrap: true,
    data:<%=counselList%>,
    columns:[[
        {field:'counselIdx',fixed:true,width:20,checkbox:true},
      	{field:'counselDate',title:'상담일자',fixed:true,width:80,align:'center'},
      	{field:'counselType',title:'상담유형',fixed:true,width:120},
      	{field:'counselor',title:'상담원',fixed:true,width:90,align:'center'},
      	{field:'counselee',title:'고객명',fixed:true,width:70,align:'center'},
      	{field:'counseleePhone',title:'전화번호',width:100,formatter:viewTitle}
    ]]
});
function viewTitle(val,rec){
	return '<span title="'+val+'">'+val+'</span>';
}

/* $('#grid_counsel').datagrid({
	onClickRow:function(){
		var row = $('#grid_counsel').datagrid('getSelected');
		if (row){
			document.form.dataCustIdx.value = row.custIdx;
			document.form.dataCustCode.value = row.custCode;
			document.form.dataCustName.value = row.custName;
			document.form.dataCustPhone.value = row.custPhone;
			document.form.dataCustBoss.value = row.custBoss;
			document.form.dataCustAddr.value = row.custAddr;
		}
	}
});  */

$('#pp').pagination({
    total:<%=counseldata.getTotalCnt()%>,
    pageSize:<%=counseldata.getPageSize()%>,
    pageNumber:<%=counseldata.getPageNo()%>,
    pageList:[20,30,50]
});
$('#pp').pagination({
	onSelectPage:function(pageNumber, pageSize){
		$(this).pagination('loading');
		document.form.pageNo.value = pageNumber;
		document.form.pageSize.value = pageSize;
		$(this).pagination('loaded');
		getList();
	}
});
</script>
</body>

</html>